package com.gec.controller;

import com.gec.dao.SysUserDao;
import com.gec.entity.SysUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LoginServlet")

public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        SysUserDao sysUserDao = new SysUserDao();
        SysUser user = sysUserDao.login(username, password);
        if (user!=null){
            response.sendRedirect("BookListServlet");
        }else {
            request.setAttribute("errorMsg","帐号或者密码错误，登陆失败");
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }
    }
}
